package Day21;

import java.util.Scanner;
import java.util.Stack;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-10-12
 * Time: 20:08
 * To BE A Better Person-2020-3-2
 */
public class TestDemo2 {
    /**
     * 
     * @param songs
     * @return 以下两个操作返回的都是光标的位置
     */
    public static int pageEnd=4;
    public static boolean flag=false;
    private static void printSong(int[] songs,int tag){
        Stack<Integer> s=new Stack<>();
        int time=4;
        while(time>0){
            s.push(songs[tag-1]);
            if(tag == 1){
                tag=songs.length;
            }else if(tag == songs.length){
                tag=1;
            }else{
                tag--;
            }
            time--;
        }
        while(!s.empty()){
            System.out.print(s.pop());
        }
    }
    private static int songDown(int[] songs,int tag){
       if(tag == songs.length-1){
           tag=0;
           pageEnd=4;
       }else{
           tag++;
       }
       if(songs[tag] % 5 == 0){
           if (pageEnd == songs.length){
               pageEnd=1;
           }else{
               pageEnd++;
           }

       }

       return tag;
    }
    private static int songUp(int[] songs,int tag){
        if(tag == 0){
            tag=songs.length-1;
            pageEnd=songs.length;
        } else {
            tag--;
        }
        if(songs[tag] % 5 == 0){
            if (pageEnd == 1){
                pageEnd=songs.length;
            }else{
                pageEnd--;
            }

        }
        return tag;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
        int[] songs=new int[num];
        String command=sc.next();
        int tag=0;

        //给数组的每个格子给一个数
        for (int i = 0; i < songs.length; i++) {
            songs[i]=i+1;
        }
        //开始
        for (int i = 0; i < command.length(); i++) {
            if(command.charAt(i)=='U'){
                tag=songUp(songs,tag);
            }else {
                tag=songDown(songs,tag);
            }
        }
        //打印四首
        printSong(songs,tag);
        System.out.println();
        System.out.print(songs[tag]);
    }
}
